package com.birdboot.core;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

public class ClientHandler implements Runnable{
    private Socket socket;
    public ClientHandler(Socket socket){
        this.socket=socket;
    }
    public void run(){
        try {
            InputStream in=socket.getInputStream();
            int d;
            char pre='a',cur='a';//pre表示上次读取的字符，cur表示本次读取的字符
            StringBuilder builder=new StringBuilder();
            while ((d=in.read())!=-1){
                if(pre==13&&cur==10){
                    break;
                }
                builder.append(cur);
                pre=cur;
            }
            String line=builder.toString().trim();
            System.out.println("请求行："+line);
            String[] data=line.split("\\s");
            String method=data[0];
            String uri=data[1];
            String protocol=data[2];

            System.out.println("mehtod:"+method);
            System.out.println("uri:"+uri);
            System.out.println("protocol:"+protocol);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
